package com.mattmckay.server;

import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;



public class ServerTest {
Server server;
TestAwsClass testawsclass;
private String pdfbucket = "bucket.pdf";
private String pngbucket = "bucket.png";
private String testsqs = "https://queue.amazonaws.com/277957951592/test";
	
	@Before
	public void setUp() throws Exception {
		server = Server.getInstance();
		testawsclass = new TestAwsClass();
	}

	@After
	public void tearDown() throws Exception {
	
	}
	
	@Test
	public void ServerPutObjectTest() throws IOException{
		server.putObject(Convert.FileToByteArray("test.png"), "test.png");
		byte[] image = testawsclass.PullS3Object("test.png", pngbucket);
		assertArrayEquals(Convert.FileToByteArray("test.png"),image);
	}
	
	@Test
	public void ServerGetObjectTest() throws IOException{
		testawsclass.PushS3Object(Convert.FileToByteArray("test.png"), "test.png", pdfbucket);
		InputStream inputstream = server.getObject(testawsclass.CreateMessage("test.png"));
		assertArrayEquals(Convert.FileToByteArray("test.png"), Convert.InputStreamToByteArray(inputstream));
	}
	
	@Test
	public void ServerFindBucketTest() throws IOException{
		testawsclass.CreateBucket("bucket.test");
		assertEquals(server.FindBucket("bucket.test"),true);
		testawsclass.DeleteBucket("bucket.test");
	}
	
	
	//THIS METHOD CANNOT BE TESTED MORE THAN ONCE EVERY 60 SECONDS!
	@Test
	public void ServerFindQueueTest() throws InterruptedException
	{
	
	 testawsclass.CreateQueue("test");
	 Thread.sleep(2000);
	 assertTrue(server.FindQueue(testsqs));
	 System.out.println(server.FindQueue(testsqs));
	 testawsclass.DeleteQueue(testsqs);
	 
	}

}
